home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2490 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: quick decision: is n a power of 2?
  5. Date: Sun, 21 Jan 96 19:35:22 GMT
  6. Organization: none
  7. Message-ID: <822252922snz@genesis.demon.co.uk>
  8. References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca> <4dpian$gij@oxy.rust.net> <9601201820.AA01752@dxmint.cern.ch>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <9601201820.AA01752@dxmint.cern.ch>
  15.            danpop@mail.cern.ch "Dan Pop" writes:
  16.  
  17. >I don't think so.  ~number & number will _always_ give 0.  -number & number
  18. >will actually work, except for the case when number == 0.  That is,
  19. >assuming a two's complement implementation.  On a one's complement or
  20. >sign-magnitude implementation it won't work at all.
  21.  
  22. If you go back to the original question number is an unsigned long.
  23. Therefore sighed integer representations are not really relevant and
  24. -number & number does what is expected. As I understand it ULONG_MAX is
  25. guaranteed to be of the form 2^^n - 1.
  26.  
  27. -- 
  28. -----------------------------------------
  29. Lawrence Kirby | fred@genesis.demon.co.uk
  30. Wilts, England | 70734.126@compuserve.com
  31. -----------------------------------------
  32.